<?php
class memberController extends commonController{
	public function __construct(){
		parent::__construct();
		$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
		$searchUserInfo = $this->searchUserInfo($uid);
		$this->assign('searchUserInfo', $searchUserInfo);
		if($_GET['uid']== ''){
			$this->success('更多信息请登录后访问', './');
		}
	}
	public function index(){
		//获取id更具uid 判断读取显示用户页面信息
			//更具uid 查询显示首页信息
			//获取get uid
		$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
		//获取用户信息
		$searchUserInfo = $this->searchUserInfo($uid);
		$this->assign('searchUserInfo', $searchUserInfo);
		//获取用户问题信息
		$searchUserAskInfo = $this->searchUserAskInfo($uid);
		$this->assign('searchUserAskInfo', $searchUserAskInfo);	
		
		//获取用户答题信息
		$searchUserAnswerInfo = $this->searchUserAnswerInfo($uid);
		$this->assign('searchUserAnswerInfo', $searchUserAnswerInfo);	

		$this->display();
	}
		
	public function myask(){
		$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
		//获取用户问题信息
		$myAsk = M('hd_ask')->query("select * from hd_ask as ask join hd_category as cate on  ask.cid=cate.cid where uid='{$uid}' and ask.solve=0");
		$this->assign('myask', $myAsk);
		$myAskSolve = M('hd_ask')->query("select * from hd_ask as ask join hd_category as cate on  ask.cid=cate.cid where uid='{$uid}' and ask.solve=1");
		$this->assign('myAskSolve', $myAskSolve);
		$this->display();
	}	

	public function myAnswer(){
		 if(empty($uid)){
	 		if(isset($_GET['uid'])){
	 			$uid = $_GET['uid'];
			}else if(isset($_SESSION['uid'])){
				$uid = $_SESSION['uid'];
			}
		}
	 $myAnswer=M('hd_answer')->query("select * from  hd_answer as answer join hd_ask as ask join hd_category as cate on ask.asid=answer.asid and ask.cid=cate.cid where answer.uid='{$uid}' and ask.solve=1");		
	$this->assign('myAnswer', $myAnswer);
		$this->display();
	}
	public function myAnswerSolve(){
		$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
		//获取用户答题信息
		$searchUserAnswerInfo = $this->searchUserAnswerInfo($uid);
		$this->assign('searchUserAnswerInfo', $searchUserAnswerInfo);
		$this->display();
	}
	public function myLevel(){
		$this->display();
	}
	public function myGold(){
		$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
		//获取用户信息
		$searchUserInfo = $this->searchUserInfo($uid);
		$this->assign('searchUserInfo', $searchUserInfo);
		$this->display();
	}
	public function myFace(){
		if(IS_POST){
			$uid = isset($_GET['uid'])?(int)$_GET['uid']:'';
			//实例化
			$upload = new Upload();
			//上传
			$upload->up();	
			$Thum = new ThumPath();
			$path =	$Thum ->ThumImg($upload->dest,C('CanvaW'),C('CanvaH'),C('createtrue'));
		//	删除生成图片
			unlink($upload->dest);
		 	$path = basename($Thum->ThumPath);
			M('hd_user')->exec("UPDATE hd_user set face='{$path}' WHERE uid='{$uid}' ");
			$this->error('上传成功');
		}
		$this->display();
	}

	/*
	 * 查询指定用户发表问题
	 */
	 public function searchUserAskInfo($uid){
		 if(empty($uid)){
	 		if(isset($_GET['uid'])){
	 			$uid = $_GET['uid'];
			}else if(isset($_SESSION['uid'])){
				$uid = $_SESSION['uid'];
			}
		}
		 return $searchUserAskInfo=M('hd_ask')->query("select * from hd_ask as ask join hd_category as cate on  ask.cid=cate.cid where uid='{$uid}'");
	 	
	 }
	/*
	 * 查询指定用户发表回答
	 */
	 public function searchUserAnswerInfo($uid){
		 if(empty($uid)){
	 		if(isset($_GET['uid'])){
	 			$uid = $_GET['uid'];
			}else if(isset($_SESSION['uid'])){
				$uid = $_SESSION['uid'];
			}
		}
	 return  $searchUserAnswerInfo=M('hd_answer')->query("select * from  hd_answer as answer join hd_ask as ask join hd_category as cate on ask.asid=answer.asid and ask.cid=cate.cid where answer.uid='{$uid}'");		
	 }
	
	
	
	
	
	
	
	
	
	
}
